import { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

import AutoImport from 'unplugin-auto-import/vite';
import Components from 'unplugin-vue-components/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        vue({
            template: {
                compilerOptions: {
                    isCustomElement: (tag) => tag === 'webview'
                }
            }
        }),
        AutoImport({
            resolvers: [ElementPlusResolver()]
        }),
        Components({
            resolvers: [ElementPlusResolver()]
        })
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src/webpage', import.meta.url))
        }
    },
    build: {
        outDir: 'dist',
        assetsDir: 'static',
        brotliSize: false, // 设置为false将禁用构建的brotli压缩大小报告。可以稍微提高构建速度
        minify: true, // 开启压缩
        rollupOptions: {
            treeshake: true // 开启 Tree Shaking，消除未使用的代码，减小最终的包大小
        }
    }
});
